<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <!-- 当item.isDone 为true时，添加comleted 类名 -->
    <li :class="{ completed: item.isDone }" v-for="item in list" :key="item.id">
      <div class="view">
        <!-- 添加了 change事件 input 状态发生改变是 触发changFun -->
        <input
          class="toggle"
          type="checkbox"
          @change="changeFun(item.id)"
          :checked="item.isDone"
        />
        <label>{{ item.name }}</label>
        <!-- 点击按钮触发 delFun -->
        <button class="destroy" @click="delFun(item.id)"></button>
      </div>
    </li>
  </ul>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  methods: {
    /* 当复选框改变时触发 */
    changeFun(id) {
      /* 向父组件传入数据 id */
      this.$emit("change", id);
    },
    /* 点 击button 触发 */
    delFun(id){
    /* 向父组件传入数据 id */
      this.$emit("delete", id);
    }
  },
};
</script>